﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using Messaging2;
using System.IO;
//using log4net;
//using log4net.Config;

//itemadd 1,'dfdf',2,'1'


//CREATE ASSEMBLY   FinPlusDBTrigger
//FROM 'C:\Projects\FinPlus\FinPlusMessaging\fpmessaging\FinPlusDBTrigger\bin\debug\FinPlusDBTrigger.dll'
//WITH PERMISSION_SET = SAFE

//ALTER DATABASE tRADEdb
//SET COMPATIBILITY_LEVEL =  100

//CREATE TRIGGER tri_Items_clr
//ON Items
//FOR INSERT
//AS
//EXTERNAL NAME FinPlusDBTrigger.CLRTrigger.showinserted


//EXEC sp_configure 'show advanced options' , '1'
//EXEC sp_configure 'clr enabled' , '1'
//EXEC sp_configure 'show advanced options' , '0';
//reconfigure


   // [SqlTrigger(Name = "showinserted", Target = "Users", Event = "FOR INSERT")]
    public class CLRTrigger
    {

        public static void showinserted()
        {
            try
            {
                SqlTriggerContext triggContext = SqlContext.TriggerContext;
                SqlConnection conn = new SqlConnection(" context connection =true ");

                conn.Open();
                SqlCommand sqlComm = conn.CreateCommand();
                SqlDataReader dr;

                sqlComm.CommandText = "SELECT Name, Value, TradeID from inserted";
                dr = sqlComm.ExecuteReader();

                Transport _conn = new Transport("239.0.0.222", 2222);

                while (dr.Read())
                {

                    object[,] array1 = { { 1212, dr[0] }, { 444, dr[1] } };
                    _conn.Publish(new Message(array1, "trigger"));
                }
            }
            catch 
            {
             
            }
        }

    }




